package com.tuzhi.auth.sys.web.controller;


import com.tuzhi.auth.sys.jpa.entity.SysOrgEntity;
import com.tuzhi.auth.sys.service.SysOrgService;
import com.tuzhi.base.web.helper.AjaxResultHelper;
import com.tuzhi.base.web.vo.AjaxResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Api(tags = "组织机构")
@RequestMapping("/org")
public class OrgController {

    @Autowired
    private SysOrgService sysOrgService;


    @ApiOperation(value = "保存数据（新增，或更新）", notes = "如果是更新的，明细行，需带上ID")
    @PutMapping("save")
    public AjaxResultVO save(@RequestBody SysOrgEntity entity) {
        sysOrgService.save(entity);
        return AjaxResultHelper.success();
    }

    @ApiOperation(value = "获取单条记录信息")
    @GetMapping("/{id}")
    public AjaxResultVO get(@PathVariable("id") Long id) {
        SysOrgEntity entity = sysOrgService.get(id);
        AjaxResultVO ajaxResultVO = AjaxResultHelper.success();
        ajaxResultVO.setData(entity);
        return ajaxResultVO;
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public AjaxResultVO del(@PathVariable("id") Long id) {
        sysOrgService.deleteById(id);
        return AjaxResultHelper.success();
    }


}
